import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBApplication.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBEngineer/YBBaseRouter/YBBaseRouter.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBLoginModule/YBLoginMainPage/YBLoginMainPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBUtils/YBTabBarMainModule/YBTabBarMainPage.dart';

class YBNavigatorUtil {

  //默认返回
  static void goDefaultBack(BuildContext context){
    Navigator.pop(context);
  }

  //返回
  static void goBack(BuildContext context){
    Navigator.pop(context);
    YBApplication.router.pop(context);
  }

  //带参数的返回
  static void goBackWithParams(BuildContext context,result){
    Navigator.pop(context,result);
  }

  //路由返回指定页面
  static void goBackUrl(BuildContext context,String title){
    Navigator.popAndPushNamed(context, title);
  }

  //跳转到主页面
  static void goHomePage(BuildContext context){
    YBApplication.router.navigateTo(context, YBBaseRouter.root,replace: true);
  }
  /// 跳转到 转场动画 页面 ， 这边只展示 inFromLeft ，剩下的自己去尝试下，
  /// 框架自带的有 native，nativeModal，inFromLeft，inFromRight，inFromBottom，fadeIn，custom
  static Future jump(BuildContext context,String title){
    return YBApplication.router.navigateTo(context, title,transition: TransitionType.native);
  }

  static Future gotransitionCustomDemoPage(BuildContext context,String title){
    var transition = (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child){
      return ScaleTransition(
        scale: animation,
        child: RotationTransition(
          turns:animation,
          child: child,
        ),
      );
    };
    return YBApplication.router.navigateTo(context, title,
        //指定是自定义动画
        transition: TransitionType.custom,
        //自定义的动画
        transitionBuilder: transition,
        //时间
        transitionDuration: const Duration(milliseconds: 600));
  }

  //使用iOS的Cupertino的转场动画，这个是修改了源码的转场动画
  //Fluro本身不带，但是Flutter自带
  static Future gotransitionCupertinoDemoPage(
      BuildContext context,String title){
    return YBApplication.router.navigateTo(context, title,transition:TransitionType.cupertino);
  }

  //跳转到主页面tabbarPage并删除当前路由
  static void goToHomeRemovePage(BuildContext context){
    Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) => YBTabBarMainPage()), (route)=> route == null);
  }

  //跳转到登录页login并删除当前路由
  static void gotToLoginRemovePage(BuildContext context){
    Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context) =>YBLoginMainPage()), (route)=> route == null);
  }

}